#ifndef _LOGMTF_H__
#define _LOGMTF_H__
#pragma once


#include <assert.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <tchar.h>
#include <string>
#include <Windows.h>
#include <assert.h>
#include <string>
#include "logmt.h"

#define LogInit()  LogmtInit();

#define LogInitCfg(X)  LogmtInitCfg((X));

#define LogSetLevel(X) LogmtSetLevel(X);

#define LogFlush() LogmtFlush();
#define LogFlushImd(X) LogmtFlushImd(X);

#define LogTraceF      if(LogmtIsLevelOn(LOGMT_LEVEL_TRACE))CMtLogFunc(LOGMT_LEVEL_TRACE,__FILE__, __FUNCTION__,__LINE__).OutMsg
#define LogDebugF      if(LogmtIsLevelOn(LOGMT_LEVEL_DEBUG))CMtLogFunc(LOGMT_LEVEL_DEBUG,__FILE__, __FUNCTION__,__LINE__).OutMsg

#define LogInfoF     if(LogmtIsLevelOn(LOGMT_LEVEL_INFO))CMtLogFunc(LOGMT_LEVEL_INFO).OutMsg
#define LogWarnF     if(LogmtIsLevelOn(LOGMT_LEVEL_WARN))CMtLogFunc(LOGMT_LEVEL_WARN).OutMsg
#define LogErrF      if(LogmtIsLevelOn(LOGMT_LEVEL_ERROR))CMtLogFunc(LOGMT_LEVEL_ERROR).OutMsg
#define LogCriticalF if(LogmtIsLevelOn(LOGMT_LEVEL_CRITICAL))CMtLogFunc(LOGMT_LEVEL_CRITICAL).OutMsg


#define LOGMT_DISRUN_TM_BG(xTmDis) \
		{\
			static int nT=0;\
			int nCurTm=timeGetTime();\
			if(nCurTm-nT>xTmDis)\
			{\
				nT=nCurTm;\
				{

#define LOGMT_DISRUN_TM_ED }}}


#define LOGMT_DISRUN_CN_BG(xTmDis)\
		{\
			static int nC=-1;\
			nC++;if(nC>xTmDis) nC=1;\
			if(nC%xTmDis==0)\
			{

#define LOGMT_DISRUN_CN_ED }}

#if defined(_MSC_VER) && (_MSC_VER <= 1200)
#define __FUNCTION__ NULL
#endif

class CMtLogFunc
{
public:
	CMtLogFunc(int nLevel);
	CMtLogFunc(int nLevel, const char* file, const char* fn, int line);
	void OutMsg(const char * format, ...);
	void OutMsg(const wchar_t * format, ...);
private:
	const char *m_fn;
	const char *m_file;
	int m_line;
	int m_nLevel;
private:
	static void GetFileName(const char *pszFilePath, std::string& strRes);
	static void StrAToW(const std::string& a, std::wstring& w);
	static void StrFormatA(std::string& str, const char* szFormat, va_list argList);
	static void StrFormatA(std::string& str, const char* szFormat, ...);
	static void StrFormatW(std::wstring& str, const wchar_t* szFormat, va_list argList);
	static void StrFormatW(std::wstring& str, const wchar_t* szFormat, ...);
};

#include "logmtf.inl"



#endif //_LOGMTF_H__
